<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">列表</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="产品名称" prop="searchValue">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="请输入产品名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="list-search btn-success" color="#5ED4D4">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="list-search">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            class="btn-success"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd()"
          >新建</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="proSampleList" border>
        <el-table-column label="序号" type="index" align="center" width="50">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品名称"  align="center" prop="name" />
        <el-table-column label="创建人"  align="center" prop="createBy" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click.native.stop="handleEdit(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              @click.native.stop="handleDetail(scope.row)"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              @click.native.stop="handleDownload(scope.row)"
            >下载二维码</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { proSampleList } from "@/api/system/proSample/proSample"
export default {
  name: "proSample",
  data() {
    return {
      loading: true,
      total: 0,
      proSampleList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: undefined,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      proSampleList(this.addDateRange(this.queryParams)).then(res => {
          this.proSampleList = res.rows
          this.total = res.total
          this.loading = false
        }
      )
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 新建
    handleAdd(){
      this.$router.push({path:"/proSample/add"})
    },
    // 修改
    handleEdit(row){
      this.$router.push({path:"/proSample/edit",query:{id: row.id}})
    },
    // 详情
    handleDetail(row){
      this.$router.push({path:"/proSample/detail",query:{id: row.id}})
    },
    // 下载
    handleDownload(row) {
      var alink = document.createElement("a")
      alink.href = row.qrAddress
      alink.click()
    }
  }
}
</script>